package com.szt.school.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szt.school.mapper.UserMapper;
import com.szt.school.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public User queryById(Long id){
        return userMapper.selectByPrimaryKey(id);
    }
    public int userUpdate(User user){
        return userMapper.updateByPrimaryKey(user);
    }
    //查询所有
    public List<User> queryAll(){
        return userMapper.selectAll();
    }
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = {Exception.class})
    public void saveUser(User user){
        userMapper.insertSelective(user);
    }
    public void deleteUserById(Long id){
        userMapper.deleteByPrimaryKey(id);
    }
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = {Exception.class})
    public PageInfo<User> getPageInfo(Integer curPage,Integer pageSize){
        PageHelper.startPage(curPage,pageSize);
        //查询
        List<User> users = userMapper.selectAll();
        return new PageInfo<>(users);
    }
}
